package com.asiainfo.dacp.datastash.orm.po.log;

import com.asiainfo.dacp.jpa.annotation.ColumnPosition;
import com.asiainfo.dacp.util.DateHelper;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name="dacp_datastash_unit_log")
@NoArgsConstructor
public class DataStashUnitEventLogPo {

    @GenericGenerator(name = "id_unit_log", strategy = "enhanced-table", parameters = {
            @Parameter(name = "table_name", value = "dacp_orm_jpa_gen"),
            @Parameter(name = "value_column_name", value = "next"),
            @Parameter(name = "segment_column_name", value = "segment_name"),
            @Parameter(name = "segment_value", value = "emp_seq"),
            @Parameter(name = "increment_size", value = "10"),
            @Parameter(name = "optimizer", value = "pooled-lo")
    })
    @GeneratedValue(generator = "id_unit_log")
    @Id
    private Long id;

    @Column(name="unit_proc_id",length = 32)
    @ColumnPosition(2)
    private String unitProcId;

    @Column(name="unit_code",length = 16)
    @ColumnPosition(3)
    private String unitCode;

    @Column(name="batch_no",length = 16)
    @ColumnPosition(4)
    private String batchNo;

    @Column(name="is_turnover",length = 1)
    @ColumnPosition(5)
    private String isTurnover;

    @Column(name="task_cnt")
    @ColumnPosition(6)
    private int taskCnt;

    @Column(name="create_dt")
    @ColumnPosition(7)
    private Date createDt=new Date();

    @Transient
    private String createDate;

    public String getCreateDate(){
        if(createDate==null || createDate.length()==0){
            createDate = DateHelper.formatDateTime(createDt);
        }
        return createDate;
    }

    public void setCreateDate(String createDate){
        this.createDate = createDate;
        createDt = DateHelper.parseDateTime(createDate);
    }


    @Column(length = 32)
    @ColumnPosition(8)
    private String message;

    @Column(length = 4)
    @ColumnPosition(9)
    private String state="0";

    public DataStashUnitEventLogPo(String unitCode, String batchNo){
        this.unitCode=unitCode;
        this.batchNo=batchNo;
    }

}
